package com.jeethink.web.controller.system;

import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.core.page.TableDataInfo;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.system.domain.InfoManagement;
import com.jeethink.system.service.IInfoManagementService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 信息系统管理Controller
 * 
 * @author jeethink
 * @date 2022-09-19
 */
@Controller
@RequestMapping("/system/management")
public class InfoManagementController extends BaseController
{
    private String prefix = "system/management";

    @Autowired
    private IInfoManagementService infoManagementService;

    @RequiresPermissions("system:management:view")
    @GetMapping()
    public String management()
    {
        return prefix + "/management";
    }

    /**
     * 查询信息系统管理列表
     */
    @RequiresPermissions("system:management:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InfoManagement infoManagement)
    {
        startPage();
        List<InfoManagement> list = infoManagementService.selectInfoManagementList(infoManagement);
        return getDataTable(list);
    }

    /**
     * 导出信息系统管理列表
     */
    @RequiresPermissions("system:management:export")
    @Log(title = "信息系统管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InfoManagement infoManagement)
    {
        List<InfoManagement> list = infoManagementService.selectInfoManagementList(infoManagement);
        ExcelUtil<InfoManagement> util = new ExcelUtil<InfoManagement>(InfoManagement.class);
        return util.exportExcel(list, "management");
    }

    /**
     * 新增信息系统管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存信息系统管理
     */
    @RequiresPermissions("system:management:add")
    @Log(title = "信息系统管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InfoManagement infoManagement)
    {
        return toAjax(infoManagementService.insertInfoManagement(infoManagement));
    }

    /**
     * 修改信息系统管理
     */
    @GetMapping("/edit/{infoId}")
    public String edit(@PathVariable("infoId") Long infoId, ModelMap mmap)
    {
        InfoManagement infoManagement = infoManagementService.selectInfoManagementById(infoId);
        mmap.put("infoManagement", infoManagement);
        return prefix + "/edit";
    }

    /**
     * 修改保存信息系统管理
     */
    @RequiresPermissions("system:management:edit")
    @Log(title = "信息系统管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InfoManagement infoManagement)
    {
        return toAjax(infoManagementService.updateInfoManagement(infoManagement));
    }

    /**
     * 删除信息系统管理
     */
    @RequiresPermissions("system:management:remove")
    @Log(title = "信息系统管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(infoManagementService.deleteInfoManagementByIds(ids));
    }
}
